/*
 * Bomb.cpp
 *
 *  Created on: 2010-05-27
 *      Author: mateusz
 */

#include "Bomb.h"

//------------------------------------------------------------------------------

Bomb::Bomb( int x, int y, time_t time, bool m ) : Element(x,y), setTime(time), mine(m) {
	range = 3;
}

//------------------------------------------------------------------------------

Bomb::~Bomb() {

}

//------------------------------------------------------------------------------

void Bomb::blow( Map* map ) {
	int i = 1;

	int n, m;
	n = getX()/20;// bo w pikselach bylo
	m = getY()/20;

	//up
	while( n-i >= 0 && i <= range ) {
		//jezeli sciana lub pudelko
		if(map->map[(n-i)*map->size+m] == 1 || map->map[(n-i)*map->size+m] == 2)
			break;

		map->map[(n-i)*map->size+m] = 20;
		i++;
	}

	if( n-1 >= 0 && map->map[(n-i)*map->size+m] == 2 ) {
		map->map[(n-i)*map->size+m] = 20;
	}

	//down
	i = 1;
	while( n+i < map->size-1 && i <= range ) {
		if( (map->map[(n+i)*map->size+m] == 1 || map->map[(n+i)*map->size+m] == 2) )
			break;
		map->map[(n+i)*map->size+m] = 20;
		i++;
	}

	if( n+i < map->size-1 && map->map[(n+i)*map->size+m] == 2 ) {
		map->map[(n+i)*map->size+m] = 20;
	}

	//left
	i = 1;
	while( m+i < map->size && i <= range ) {
		if( map->map[n*map->size+m+i] == 1 || map->map[n*map->size+m+i] == 2 )
				break;
		map->map[n*map->size+m+i] = 20;
		i++;
	}

	if( m+i < map->size && map->map[n*map->size+m+i] == 2 ) {
		map->map[n*map->size+m+i] = 20;
	}

	//right
	i = 1;
	while( m-i >= 0 && i <= range ) {
		if( map->map[n*map->size+m-i] == 1 || map->map[n*map->size+m-i] == 2 )
			break;
		map->map[n*map->size+m-i] = 20;
		i++;
	}

	if( m-i < map->size && map->map[n*map->size+m-i] == 2 ) {
		map->map[n*map->size+m-i] = 20;
	}

	map->map[n*map->size+m] = 20;
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
